﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using ShopB2C.Business.Models.Classify;

namespace ShopB2C.Business.EFCodes {
    public class EFClassifyContext : DbContext {
        /// <summary>
        /// 分类集
        /// </summary>
        public DbSet<EClassify> Classifies { get; set; }
        /// <summary>
        /// 属性集
        /// </summary>
        public DbSet<EClassifyProperty> ClassifyProperties { get; set; }
        /// <summary>
        /// 属性值集
        /// </summary>
        public DbSet<EClassifyPropertyVal> ClassifyPropertyVals { get; set; }

        static EFClassifyContext() {
            Database.SetInitializer<EFClassifyContext>(
                new CreateDatabaseIfNotExists<EFClassifyContext>());
        }

        public EFClassifyContext() {
            // 贪婪加载禁用, 延时加载启用
            this.Configuration.LazyLoadingEnabled = false;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder) {
            base.OnModelCreating(modelBuilder);
            // Map schemas
            modelBuilder.Entity<EClassify>().ToTable("Classify");
            modelBuilder.Entity<EClassifyProperty>().ToTable("ClassifyProperty");
            modelBuilder.Entity<EClassifyPropertyVal>().ToTable("ClassifyPropertyVal");


        }
    }

}
